package com.lyn.fileplus;

import android.text.TextUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 文件夹工厂
 *
 * @author Lyn 2022/12/18
 * @version 1.0.0
 */
public class FolderFactory {

    public static Map<String, Folder> stringFolderMap = new ConcurrentHashMap<>();

    public static Folder getFolder(String path, String folderName) {
        if (stringFolderMap.containsKey(folderName)) {
            return stringFolderMap.get(folderName);
        }
        FolderCore folderCore = new FolderCore(path);
        stringFolderMap.put(folderName, folderCore);
        return folderCore;
    }

    public static void removeFolder(String folderName) {
        if (TextUtils.isEmpty(folderName)) {
            throw new NullPointerException("路径不能为空!");
        }
        Folder folder = stringFolderMap.remove(folderName);
        assert folder != null;
        FileUtil.deleteFolder(folder.getPath());
    }

}
